package com.kgc.novel.controller;

import com.kgc.novel.common.Res;
import com.kgc.novel.domain.entity.BookIncome;
import com.kgc.novel.domain.entity.BookRecord;
import com.kgc.novel.domain.param.BookIncomeParam;
import com.kgc.novel.domain.param.BookRecordParam;
import com.kgc.novel.service.user.BookRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.sql.*;
import java.util.List;

/**
 * @author Wang乐俊.
 * @date 2023/5/9 0009 19:41
 * @Version: 1.0
 */
@RestController
@RequestMapping("/record")
@Slf4j
@Api("用户阅读记录管理")
@CrossOrigin
public class BookRecordController {
    @Resource
    private BookRecordService bookRecordService;

    @PostMapping("/list")
    @ApiOperation("查询全部信息")
    public Res selectList(@RequestBody(required = false) BookRecordParam bookRecordParam) {
        return bookRecordService.selectRecordAll(bookRecordParam);
    }

    @GetMapping("/select/{id}")
    @ApiOperation("查询单个信息")
    public Res selectShelf(@PathVariable("id") String id) {
        return bookRecordService.getSingleRecord(id);
    }

    @PostMapping("/add")
    @ApiOperation("新增单个信息")
    public Res addShelf(@RequestBody(required = true) BookRecord bookRecord) {
        return bookRecordService.addRecord(bookRecord);
    }

    @PutMapping("/update")
    @ApiOperation("修改单个信息")
    public Res updateShelf(@RequestBody(required = true) BookRecord bookRecord) {
        return bookRecordService.updateRecord(bookRecord);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除单个信息")
    public Res deleteShelf(@PathVariable("id") String id) {
        return bookRecordService.deleteRecord(id);
    }

    @GetMapping("/deleteAll/{ids}")
    @ApiOperation("批量删除信息")
    public Res deleteAllShelf(@PathVariable("ids") List<String> ids) {
        return bookRecordService.deleteAllRecord(ids);
    }
}
